package com.xingu.xg.controller;

import com.xingu.xg.common.consts.ComRT;
import com.xingu.xg.common.consts.ComResult;
import com.xingu.xg.common.entity.query.AddNodeQuery;
import com.xingu.xg.common.entity.query.CopyNodeQuery;
import com.xingu.xg.common.entity.query.DeleteNodeQuery;
import com.xingu.xg.common.entity.query.NodeQuery;
import com.xingu.xg.service.TreeMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/tree")
public class TreeMenuController {

    @Resource
    private TreeMenuService treeMenuService;

    @ApiOperation("查询所有菜单")
    @GetMapping("/get/menu/list")
    public ComResult getTreeMenuList() {
        return ComRT.success(treeMenuService.queryTreeMenuList());
    }

    @ApiOperation("创建向上和向下的同级菜单节点")
    @PostMapping("/add/same/menu")
    public ComResult addSameLevelTreeMenu(@RequestBody AddNodeQuery addNodeQuery) {
        treeMenuService.addSameLevelTreeMenu(addNodeQuery);
        return ComRT.success();
    }

    @ApiOperation("创建子级和父级菜单节点")
    @PostMapping("/add/difference/menu")
    public ComResult addDifferentLevelTreeMenu(@RequestBody AddNodeQuery addNodeQuery) {
        treeMenuService.addDifferentLevelTreeMenu(addNodeQuery);
        return ComRT.success();
    }

    @ApiOperation("复制菜单节点树")
    @PutMapping("/copy/menu")
    public ComResult copyTreeMenu(@RequestBody CopyNodeQuery copyNodeQuery) {
        treeMenuService.copyTreeMenu(copyNodeQuery);
        return ComRT.success();
    }

    @ApiOperation("移除菜单节点")
    @DeleteMapping("/delete/menu")
    public ComResult removeTreeMenu(@RequestBody DeleteNodeQuery deleteNodeQuery) {
        treeMenuService.removeTreeMenu(deleteNodeQuery);
        return ComRT.success();
    }
}
